package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectVisitorListListListener;
import com.longxi.tianjintianbao.model.visitor.Visitor;
import com.longxi.tianjintianbao.utils.MyUtils;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class VisitorListViewBinder extends ItemViewBinder<Visitor, VisitorListViewBinder.ViewHolder> {

    SelectVisitorListListListener listener;

    public VisitorListViewBinder(SelectVisitorListListListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_visitor_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Visitor visitor) {
        holder.mTvDate.setText("来访时间:" + (TextUtils.isEmpty(visitor.getVisitdate()) ? "--" : visitor.getVisitdate()));
        holder.mTvName.setText("拜访对象:" + visitor.getMaster());
        holder.mTvAddress.setText("所属项目:" + visitor.getBuild());
        holder.mTvLeftContent.setText("来访人:" + visitor.getVisitorname() + "    拜访人:" + visitor.getMaster());
        holder.mTvRightContent.setText("来访事由:" + visitor.getCause());
        holder.mTvApplyTime.setText("预约时间:" + visitor.getReceivedate());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(visitor);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvName;
        TextView mTvDate;
        TextView mTvAddress;
        TextView mTvLeftContent;
        TextView mTvRightContent;
        TextView mTvApplyTime;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvName = itemView.findViewById(R.id.tvName);
            mTvDate = itemView.findViewById(R.id.tvDate);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
            mTvLeftContent = itemView.findViewById(R.id.tvLeftContent);
            mTvRightContent = itemView.findViewById(R.id.tvRightContent);
            mTvApplyTime = itemView.findViewById(R.id.tvApplyTime);
        }
    }
}
